package com.fatmeraid.controller.order;

import com.fatmeraid.common.model.PageResult;
import com.fatmeraid.common.result.Result;
import com.fatmeraid.domain.Order;
import com.fatmeraid.domain.Policy;
import com.fatmeraid.service.OrderService;
import com.fatmeraid.vo.order.AddOrderVo;
import com.fatmeraid.vo.order.GetOrderVo;
import com.fatmeraid.vo.order.UpdateOrderVo;
import com.fatmeraid.vo.order.UpdateStatusVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@Tag(name = "订单管理")
@RestController
@RequestMapping("/order")
public class OrderController {

	@Autowired
	private OrderService orderService;
	@Operation(summary = "添加订单")
	@PostMapping
	public Result<String> addOrder(@RequestBody AddOrderVo addOrderVo) {
		String ret = String.valueOf(orderService.addOrder(addOrderVo));

		return Result.ok(ret);
	}

	@Operation(summary = "获取订单列表")
	@GetMapping
	public Result<PageResult<Order>> getOrderList(GetOrderVo getOrderVo) {
		PageResult<Order> ret = orderService.getOrderList(getOrderVo);
		return Result.ok(ret);
	}

	@Operation(summary = "获取订单详情")
	@GetMapping("/{orderId}")
	public Result<Order> getOrderDetail(@PathVariable Long orderId) {
		Order order = orderService.getOrderDetail(orderId);
		return Result.ok(order);
	}

	@Operation(summary = "修改订单收货信息")
	@PutMapping("/data")
	public Result<String> updateOrder(@RequestBody UpdateOrderVo updateOrderVo) {
		boolean ret = orderService.updateOrder(updateOrderVo);
		if (!ret){
			return Result.fail();
		}
		return Result.ok();
	}
	@Operation(summary = "修改订单状态")
	@PutMapping("/status")
	public Result<String> updateOrderStatus(@RequestBody UpdateStatusVo updateStatusVo) {
		boolean ret = orderService.updateOrderStatus(updateStatusVo);
		if (!ret){
			return Result.fail();
		}
		return Result.ok();
	}


	@Operation(summary = "删除订单")
	@DeleteMapping("/{orderId}")
	public Result<String> deleteOrder(@PathVariable String orderId) {
		boolean ret = orderService.deleteOrder(orderId);
		if (!ret){
			return Result.fail();
		}
		return Result.ok();
	}

	// 获取自己购买的订单
	@Operation(summary = "获取自己下单的订单")
	@GetMapping("/getMyOrder")
	public Result<PageResult<Order>> getMyOrder(GetOrderVo getOrderVo) {
		PageResult<Order> ret = orderService.getMyOrder(getOrderVo);
		return Result.ok(ret);
	}


}
